//
//  BKMyOrderLogisticsTableViewCell.m
//  bestkeep
//
//  Created by mac on 16/12/15.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKMyOrderLogisticsTableViewCell.h"
#import "BK_OD_Tool.h"
#import "BK_OD_Color.h"
@implementation BKMyOrderLogisticsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        
        [self setTranslatesAutoresizingMaskIntoConstraints:YES];
        
        _lineView = [UILabel new];
        _lineView.backgroundColor = RGB(178, 178, 178);
        [self.contentView addSubview:_lineView];
        
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView.mas_left).offset(40);
            make.width.mas_equalTo(@(1));
            make.bottom.mas_equalTo(self.contentView.mas_bottom);
            make.top.mas_equalTo(self.contentView.mas_top);
        }];
        
        _collectLabel = [UILabel new];
        _collectLabel.backgroundColor = RGB(216, 216, 216);
        _collectLabel.layer.cornerRadius = 4.5;
        _collectLabel.layer.masksToBounds = YES;
        [self.contentView addSubview:_collectLabel];
        
        [_collectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.contentView.mas_top).offset(0);
            make.centerX.mas_equalTo(_lineView.mas_centerX);
            make.width.mas_equalTo(@(9));
            make.height.mas_equalTo(@(9));
        }];
        
        _msgLabel = [UILabel new];
        _msgLabel.font = [UIFont systemFontOfSize:14.0];
        _msgLabel.numberOfLines = 0;
        _msgLabel.textColor = kOrderBlack1;
        [self.contentView addSubview:_msgLabel];
        
        
        [_msgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.contentView.mas_top);
            make.left.mas_equalTo(_lineView.mas_right).offset(40);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-ApplicationBackGauge);
            //            make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-45);
        }];
        
        _timeLabel = [UILabel new];
        _timeLabel.textColor = kOrderBlack1;
        _timeLabel.font = [UIFont systemFontOfSize:12.0];
        [self.contentView addSubview:_timeLabel];
        
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_msgLabel.mas_bottom).offset(5);
            make.left.mas_equalTo(_lineView.mas_right).offset(40);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-ApplicationBackGauge);
            //            make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-25);
        }];
    }
    return self;
}

//赋值 and 自动换行,计算出cell的高度
-(void)setIntroductionText:(NSString*)text{
    //获得当前cell高度
    CGRect frame = [self frame];
    //文本赋值
    self.msgLabel.text = text;
    
    CGSize labelSize = [self sizeWithString:self.msgLabel.text font:self.msgLabel.font maxSize:CGSizeMake(300, 1000)];
    self.msgLabel.frame = CGRectMake(self.msgLabel.frame.origin.x, self.msgLabel.frame.origin.y, labelSize.width, labelSize.height);
    
    //计算出自适应的高度
    frame.size.height = labelSize.height + 35;
    
    self.frame = frame;
}

-(CGSize)sizeWithString:(NSString *)str font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *dict = @{NSFontAttributeName : font};
    CGSize size = [str boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
    return size;
}


@end
